<?php

//Yii::import('user.controllers.UserBaseController');

class ActionController extends Controller
{

	public function actionForgot()
	{
        if(isset($_POST['phone'])){
            $phone = $_POST['phone'];
            $account = Account::model()->findByAttributes(array('phone' => $phone));
            if($account){
                $new_pass = substr(md5(time()), 0, 4);
                $sms = Yii::app()->smsCentral;
                $sms->sendMT($phone, "Ban vua reset mat khau tai he thong tichdiem.vn. Tai khoan: {$phone}. Mat khau moi: {$new_pass}");
                $password_crypt = md5($new_pass.Yii::app()->params['passwordKey']);
                $accountAuth = AccountAuth::model()->findByAttributes(array('phone' => $phone));
                $accountAuth->password = $password_crypt;
                $accountAuth->save();
                
                Yii::app()->user->setFlash('reset_password_phone', $phone);
            }else{
                Yii::app()->user->setFlash('not_exist_phone', $phone);
            }
            $this->redirect(Yii::app()->request->requestUri);
        }
        $this->pageTitle = "Tài khoản | Quên mật khẩu";
		$this->render('forgot');
	}
}

?>
